package com.example.demo.tools;

import java.util.Random;

/**
 * @Classname RandomTools
 * @Description TODO
 * @Date 2020/12/29 9:51
 * @Created by 新
 */
public class RandomTools {
    /**
     * 方法1：生成随机数字和字母组合
     *
     * @param length
     * @return
     */

    public static String getCharAndNumr(int length) {

        Random random = new Random();
        StringBuffer valSb = new StringBuffer();
        String charStr = "0123456789abcdefghijklmnopqrstuvwxyz";
        int charLength = charStr.length();

        for (int i = 0; i < length; i++) {

            int index = random.nextInt(charLength);

            valSb.append(charStr.charAt(index));

        }

        return valSb.toString();

    }

}
